<?php
require_once("/../userClass.php");
require_once("/../userHelper.php");
require_once("/../databaseHelper.php");
require_once("/../resetDatabase.php");

class userClassTest extends PHPUnit_Framework_TestCase
{
	public function testAddUser()
	{
		$username = "AAA AddTestUser 001";
		$password = "password";
		userClass::addUser($username, $password);
		
		$allNamesDatabase = userHelper::getAllUsernames();
		
		$allNamesText = array("Han Solo", "Luke Skywalker", "Gandalf", "Aragorn", "Frodo", "Mal Reynolds", "Phu", "River", "Daniel", "Anthony", "Brittany", "Brionna", "Chris", "Mike", "Elizabeth", $username);
		
		$this->assertEquals($allNamesText, $allNamesDatabase);
		
		userClass::deleteUser("AAA AddTestUser 001");
	}
	
	public function testDeleteUser()
	{
		$username = "AAA AddTestUser 002";
		$password = "password";
		userClass::addUser($username, $password);
		userClass::deleteUser("AAA AddTestUser 002");
		
		$allNamesDatabase = userHelper::getAllUsernames();
		
		$allNamesText = array("Han Solo", "Luke Skywalker", "Gandalf", "Aragorn", "Frodo", "Mal Reynolds", "Phu", "River", "Daniel", "Anthony", "Brittany", "Brionna", "Chris", "Mike", "Elizabeth");
		
		$this->assertEquals($allNamesText, $allNamesDatabase);
	}
	
	public function testLoginUserCorrect()
	{
		$username = "Brittany";
		$password = "password";
		
		$usernameDatabase = userClass::loginUser($username, $password);
		
		$this->assertEquals(true, $usernameDatabase);
	
		
		$username = "";
		$password = "password";
		
		$usernameDatabase = userClass::loginUser($username, $password);
		
		$this->assertEquals(false, $usernameDatabase);
	}
	
	public function testGetUsernameByID()
	{
		$usernameText = "Han Solo";
		
		$usernameDatabase = userClass::getUsernameByID(1);
		
		$this->assertEquals($usernameText, $usernameDatabase);
		
		
		
		$usernameText = null;
		
		$usernameDatabase = userClass::getUsernameByID(0);
		
		$this->assertEquals($usernameText, $usernameDatabase);
	}
	
	public function testGetIDByUsername()
	{
		$username = 'Han Solo';
		
		$databaseID = userClass::getIDByUsername($username);
		
		$this->assertEquals(1, $databaseID);
		
		
		$username = null;
		
		$databaseID = userClass::getIDByUsername($username);
		
		$this->assertEquals(null, $databaseID);
	}
	
	public function testGetUserType()
	{
		$ID = 1;
		
		$userType = userClass::getUserType($ID);
		
		$this->assertEquals(1, $userType);
		
		
		$ID = 0;
		
		$userType = userClass::getUserType($ID);
		
		$this->assertEquals(1, $userType);
	}
}